package server

import (
	"context"
	"xr-game-server/core/constants/common"
	"xr-game-server/core/httpserver"
	"xr-game-server/dao/zonedao"
	"xr-game-server/dto/serverdto"
	"xr-game-server/entity"
	"xr-game-server/errercode"
)

func SaveZone(ctx context.Context, req *serverdto.SaveZoneReq) (res bool, err error) {
	if req.Data.ID == common.Zero {
		return false, errercode.CreateCode(errercode.EmptyZoneId)
	}
	if req.Data.Name == "" {
		return false, errercode.CreateCode(errercode.EmptyString)
	}
	zonedao.Save(req.Data)
	return true, nil
}

func PageZone(ctx context.Context, req *serverdto.GetZoneReq) (res *httpserver.CMSQueryResp, err error) {
	return httpserver.NewCMSQueryResp(zonedao.Page(req)), nil
}

func GetComboData() (data []*entity.Zone, err error) {
	data = make([]*entity.Zone, common.Zero)
	_, data = zonedao.Page(&serverdto.GetZoneReq{})
	return data, nil
}
